<template>
	<view>
		<div class="shop_kind">
			<view class="shop_header">
				<!-- <u-search shape="square" :showAction="false" bgColor="white" inputAlign="left" height="40"></u-search> -->
				<view @click="jumpSearch" class="index_search">
					<u-search bgColor="white" :showAction="false" placeholder="请输入关键字"></u-search>

				</view>


			</view>
			<view class="shop_main">
				<view class="content_title">
					商品总类
				</view>
				<u-scroll-list indicatorColor="#ffe9f2" indicatorActiveColor="#ff78a2">
					<view class="content1" v-for="(item, index) in kindList" :key="index">
						<image class="content_img" src="../../static/img/demo.webp" mode=""></image>
						<view class="mask" @click="changeActive(index)" :class="active==index?'active':''">
							{{item}}
						</view>
					</view>
				</u-scroll-list>
				<view class="hot_list">
					<view class="hot_tab" v-for="item in shopList">
						<view class="tab_img" @click="jumpDetial(item.item_id)">
							<image :src="item.item_img
							" mode="aspectFill"></image>
						</view>
						<view class="tab_txt">
							<view class="txt_title">{{item.item_shops}}</view>
							<view class="txt_price">￥{{item.item_price}}</view>
						</view>
					</view>

				</view>

			</view>
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active: 0,
				// list: [{
				// 	thumb: "https://cdn.uviewui.com/uview/goods/1.jpg"
				// }, {
				// 	thumb: "https://cdn.uviewui.com/uview/goods/2.jpg"
				// }, {
				// 	thumb: "https://cdn.uviewui.com/uview/goods/3.jpg"
				// }, {
				// 	thumb: "https://cdn.uviewui.com/uview/goods/4.jpg"
				// }, {
				// 	thumb: "https://cdn.uviewui.com/uview/goods/5.jpg"
				// }]
				kindList: [
					"粘土人", "TV动画", "POP UP", "GOOD SMILE", "Corocoroid", "比例", "MODEROID", "粘土娃",
					"figma", "「现货GSC」"
				],
				shopList: []
			};
		},
		async onShow() {
			uni.showLoading({
				title: "加载中..."
			})
			await this.getList()
			uni.hideLoading()
		},
		methods: {
			async getList() {
				await uniCloud.callFunction({
					name: "kind_list_shop",
					data: {
						item_title: this.kindList[this.active]
					}

				}).then((res) => {
					// this.hotList = res.result.data
					let newArr = res.result.data
					console.log(newArr)
					this.shopList = newArr
					uni.hideLoading()
				})
			},
			changeActive(i) {
				if (this.active != i) {
					this.active = i
					uni.showLoading({
						title: "加载中..."
					})
					this.getList()
				}

			},
			jumpDetial(sid) {
				console.log(sid);


				uni.setStorageSync("sid", sid)
				uni.removeStorageSync("flat")
				uni.navigateTo({
					url: `/pages/detail/detail?sid=${sid}&flat=0`
				})
			},
			jumpSearch() {
				console.log("收一下")
				uni.navigateTo({
					url: "/pages/search/search"
				})
			}
		},
	}
</script>

<style lang="scss">
	.hot_list {
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;

		.hot_tab {
			background-color: white;
			height: 472rpx;
			width: 326rpx;
			margin-bottom: 20rpx;
			border-radius: 16px;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			overflow: hidden;

			.tab_img {
				height: 364rpx;
				width: 100%;
				background-color: lightblue;
				box-sizing: border-box;
				border: 4px solid white;
				border-radius: 16px 16px 0 0;
				overflow: hidden;

				image {
					height: 100%;
					width: 100%;
				}
			}

			.tab_txt {
				border-top: 1px solid whitesmoke;
				height: 108rpx;
				width: 100%;
				background-color: white;

				.txt_title {
					margin-left: 20rpx;
					margin-top: 10rpx;
					font-size: 16px;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}

				.txt_price {
					color: #ff78a2;
					margin-left: 20rpx;
					font-size: 14px;
				}
			}
		}
	}


	.shop_main {
		margin: 40rpx 40rpx 0;

		.content_title {
			margin: 20rpx 0 24rpx;
			font-size: 18px;
		}

		.content1 {
			height: 180rpx;
			background-color: #999;
			margin-right: 30rpx;
			position: relative;

			.mask {
				position: absolute;
				top: 0;
				left: 0;
				background-color: rgba(0, 0, 0, 0.5);
				color: white;
				height: 100%;
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 13px;
				transition: .3s;

				&.active {
					background-color: rgba(0, 0, 0, 0.2);
				}
			}

			.content_img {
				height: 100%;
				width: 90px;
			}
		}
	}

	.shop_kind {
		background-color: #f2f3f3;
		;
		width: 100%;
		min-height: 93vh;

		.shop_header {
			margin: 0 20px;
			padding-top: 20px;

			.index_search {
				height: 90rpx;
				display: flex;
				justify-content: space-between;

				.inp {
					height: 100%;
					border-radius: 12px;
					background-color: white;
					line-height: 90rpx;
					width: 100%;
					display: flex;
					align-items: center;

					image {
						height: 40rpx;
						margin-left: 10px;
						width: 40rpx;
					}

					text {
						margin-left: 10px;
						font-size: 14px;
						color: #999;

					}
				}

			}
		}

	}
</style>